package hot_100;

public class 两两交换链表中的节点 {
    public static void main(String[] args) {
    }

    public ListNode swapPairs(ListNode head) {
        ListNode ans = new ListNode();
        ListNode st;
        ListNode ed;
        st = ans;
        ed = head;
        ans.next = head;
        int cnt = 0;
        while (ed != null && ed.next != null) {
            cnt = cnt % 3;
            if (cnt == 0) {
                st.next = ed.next;
                ListNode temp = ed.next;
                ed.next = temp.next;
                temp.next = ed;
            } else {
                st = ed;
                ed = ed.next;
            }
            cnt++;
        }
        return ans.next;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
